package hanjia;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/15-下午9:44
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode376 {

    public int wiggleMaxLength(int[] nums) {

        int result = 0;
        if (nums.length == 1) {
            return 1;
        }
        if (nums.length == 2) {

            return nums[0] == nums[1] ? 1 : 2;
        }

        ArrayList<Integer> list = new ArrayList<>();
        list.add(nums[0]);
        for (int i = 1; i < nums.length; i++) {
            if (nums[i]==nums[i-1]){
                continue;
            }
            list.add(nums[i]);
        }


        if (list.size()==1){
            return 1;
        }



        for (int i = 1; i < list.size() - 1; i++) {

          if ((list.get(i)-list.get(i-1))*(list.get(i+1)-list.get(i))<0){
              result++;
          }


        }
        return result+2;


    }
}
